Route::get('sitemap.xml', 'SitemapController@index')->name('sitemapxml');Now you can create SitemapController.php with artisan command php artisan make:controller SitemapController
public function index() { $page = Post::where('status', '=', 1)->get();Now please create a view file in
return response()->view('sitemap_xml', ['page' => $page])->header('Content-Type', 'text/xml'); }
<?php echo '<?xml version="1.0" encoding="UTF-8"?>'; ?> <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd"> @foreach ($page as $post) <url> <loc>{{ url($post->page_slug) }}</loc> <lastmod>{{ $post->updated_at->tz('UTC')->toAtomString() }}</lastmod> <priority>0.9</priority> </url> @endforeach </urlset>
We are Recommending you:
- Custom 404 Page In Laravel 8
- Why Use the Repository Pattern in a Laravel Application
- Laravel 8 multi auth login
- How to change timezone in laravel 8
- Laravel 8/7 Overwriting the Default Pagination System
- Integrate Zoho SMTP Mail Configurations in Laravel?
- Laravel remove public from url
- Laravel 8 .htaccess file for php 8
- Laravel's .htaccess to remove "public" from URL
Step Out of Your Comfort Zone: 10 Powerful...
Is Mobile Reels Harming Our Children? Here's...
Simple body language tricks1. Stand with...
Best Free Websites to Learn CodingIf you...
commonly, we remove rows from the database...
these are following steps to remove...
1. What is Git, and why is it important?Git...
for hide option value on other select...
.marginspace li { margin-bottom:16px}Srimad...